package com.wanbangee.marksystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.UStudent;
import com.wanbangee.marksystem.service.UStudentService;

@RequestMapping("/studentManage")
@RestController
public class UStudentController {

	@Autowired
	private UStudentService uStudentService;

	/**
	 * 新增学生
	 * 
	 * @param student
	 * @return
	 */
	@RequestMapping(value = "/insertStudent", method = RequestMethod.POST)
	public Map<String, Object> addStudent(UStudent student) {
		Map<String, Object> map = new HashMap<>();
		if (uStudentService.addStudent(student) == false) {
			map.put("code", 1003);
			map.put("msg", "操作失败");
			return map;
		}

		map.put("student", student);
		map.put("code", 1001);
		map.put("msg", "添加成功");

		return map;
	}

	/**
	 * 更新学生
	 * 
	 * @param student
	 * @return
	 */
	@RequestMapping(value = "/updateStudent", method = RequestMethod.PUT)
	public Map<String, Object> updateStudent(UStudent student) {
		uStudentService.updateStudent(student);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("student", student);
		map.put("code", 1001);
		map.put("msg", "添加成功");

		return map;
	}

	/**
	 * 通过学生ID查询学生信息
	 * 
	 * @param stuId
	 * @return
	 */
	@RequestMapping(value = "/selectStudentByStuId", method = RequestMethod.GET)
	public Map<String, Object> selectStudentByStuId(Integer stuId) {

		Map<String, Object> map = new HashMap<>();
		UStudent student = this.uStudentService.selectStudentByStuId(stuId);
		map.put("student", student);
		map.put("code", 1001);
		map.put("msg", "查询成功");
		return map;
	}

	/**
	 * 通过学校Id年纪Id查询学生
	 * 
	 * @param schId
	 * @param graId
	 * @return
	 */
	@RequestMapping(value = "/selectStudentBySchIdAndGradId", method = RequestMethod.GET)
	public Map<String, Object> selectStudentBySchIdAndGradId(Integer schId, Integer graId) {

		Map<String, Object> map = new HashMap<>();
		List<UStudent> student = this.uStudentService.selectStudentBySchIdAndGradId(schId, graId);
		map.put("student", student);
		map.put("code", 1001);
		map.put("msg", "查询成功");
		return map;
	}

	@GetMapping("/selectStudentBySchId")
	public Map<String, Object> selectStudentBySchId(Integer schId) {

		Map<String, Object> map = new HashMap<>();
		List<UStudent> student = this.uStudentService.selectStudentBySchId(schId);
		map.put("student", student);
		map.put("code", 1001);
		map.put("msg", "查询成功");
		return map;
	}
	
	
	@GetMapping("/selectStudentBySchIdAndGradIdAndClaId")
	public Map<String, Object> selectStudentBySchIdAndGradIdAndClaId(Integer schId, Integer graId,Integer claId) {

		Map<String, Object> map = new HashMap<>();
		List<UStudent> student = this.uStudentService.selectStudentBySchIdAndGradIdAndClaId(schId, graId, claId);
		map.put("student", student);
		map.put("code", 1001);
		map.put("msg", "查询成功");
		return map;
	}
	
	@DeleteMapping("/deleteStudent")
	public Map<String, Object> deleteStudent(Integer stuId) {

		Map<String, Object> map = new HashMap<>();
		
		map.put("code", this.uStudentService.deleteStudent(stuId));
		map.put("msg", "删除成功");
		return map;
	}
}
